package com.motu.vertx.module.utility.base;

import com.motu.vertx.module.utility.toolset.TimeUtils;
import com.motu.vertx.module.utility.toolset.Tool;
import io.vertx.core.json.JsonObject;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class UtilityConstant {

    // 设备相关key
    public static final String GATE_OBJ_DEVICE_ID = "deviceid";// 客户端登录时上行的设备id
    public static final String GATE_OBJ_DEVICE_ID_TD = "device_id_td";// 客户端登录时上行的数数sdk采集设备id
    public static final String GATE_OBJ_TIMEZONE = "tz";// 客户端登录时上行的当前时区
    public static final String GATE_OBJ_DISTINCT_ID = "distinct_id";//数数的账号id
    public static final String GATE_OBJ_IP = "ip";//客户端Ip
    public static final String GATE_OBJ_RYOSVERSION = "ryosversion";//操作系统版本
    public static final String GATE_OBJ_RYOS = "ryos";//操作系统
    public static final String GATE_OBJ_RYDEVICETYPE = "rydevicetype";//设备型号
    public static final String GATE_OBJ_APP_VERSION = "app_version";//app版本
    public static final String GATE_OBJ_PRODUCER = "producer";//生产商
    public static final String GATE_OBJ_NETWORK_TYPE = "network_type";//网络类型
    public static final String GATE_OBJ_OPERATOR = "operator";//运营商
    public static final String GATE_OBJ_PLATFORM = "platform";//平台号
    public static final String GATE_OBJ_CHANNEL = "channel";//渠道号

    /***
     * 从gateObj获取某一个属性值
     * @param gobj
     * @param key 属性key
     * @return
     */
    public static String getValueFromGateObj(JsonObject gobj, String key) {
        if (gobj != null && gobj.containsKey(key)) {
            return gobj.getString(key);
        }
        return "";
    }

    /**
     * 获取转换时区后的时间
     *
     * @param timezone 目标时区
     * @return
     */
    public static String getEventTime(String timezone, int timeZoneOffset) {
        if (!Tool.isEmpty(timezone)) {
            int targetTimeZoneOffset = Tool.rint(Float.parseFloat(timezone) * 3600 * 1000);//小时换算成毫秒
            //时区不相等
            if (targetTimeZoneOffset != timeZoneOffset) {
                long curTime = System.currentTimeMillis();
                curTime -= (timeZoneOffset - targetTimeZoneOffset);
                return TimeUtils.getMsTimeFullStr(curTime);
            }
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        return sdf.format(Calendar.getInstance().getTime());
    }

}
